#!/usr/bin/python
# -*- coding:utf-8 -*-
#计数排序
#@author: wklken@yeah.net



def count_sort(l):
    
    print l
    index = [0] * len(l)
     
    for i in range(len(l)):
        for j in range(i):
            if l[j] <= l[i]:
                index[i] += 1
            else:
                index[j] += 1
    result = [0] * len(l)
    for i in range(len(l)):
        result[index[i]] = l[i]
    print result
    
l = [8, 4, 3, 7, 6, 5, 2, 1]
count_sort(l)     
        